package NG::Gen::Users;
use strict;
use warnings;
use utf8;

use Extend;
use NG::Sys::Cfg;

use base 'NG::Sys::Cached::Mixed';

sub new {
    my ($class,%args) = @_;
	my $app = $args{app};

	$args{tune} = config("users");
	$args{cache} = $app->get_cache(%{$args{tune}{cache}});
	my @kp = keys %{$args{tune}{param}};
	@args{@kp} = @{$args{tune}{param}}{@kp};
	my $self = Class->SUPER::new(%args);
	return $self;
}
sub init {
	my ($self) = @_;
	$self->SUPER::init;
	my $tables = $self->{tune}{tables};
	for(@$tables){
		$self->add_table($_);
	}
	my $ext = $self->{tune}{extern};
	for(@$ext){
		$self->add_extern($_);
	}
}
sub get_by_id{
	my $self = shift;
	return $self->get_obj(@_);
}
sub get_by_login {
	my $self = shift;
	return $self->get_by_name(@_);
}
sub remove_user {
	my ($self,$user_id) = @_;
	my $user = $self->get_obj($user_id);
	$self->{record_class}->remove_user($self,$user);
	$user->remove;
}
sub create_user {
	my ($self) = @_;
	my $user = $self->{record_class}->create_user(@_);
	my $oUser = $self->create(0,$user);
	return $oUser;
	
}
sub check_login {
	my $self = shift;
	return $self->check_for_name(@_);
}


1;
